<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var removeDuplicates = function (nums) {
      const RM = 2; // 最大重复次数
      let slow = 0; // 慢指针 - 写

      // fast 快指针 - 读
      for (fast in nums) { // 快指针移动
        if (nums[fast] != nums[slow - RM]) { // 写入数据条件
          nums[slow] = nums[fast]; // 慢指针写入数据
          slow++; // 慢指针移动
        }
      }

      return slow;
    };
    console.log(removeDuplicates([1, 1, 1, 2, 2, 3]));
  </script>
</body>

</html>